package com.lmk;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

public class StudentBiz {
    Student[] students=new Student[5];
    private int size;
    public void  addStudent(Student student){
       students[size++]=student;
    }
    public void  sortByAge(){
        for (int i = 0; i <size-1 ; i++) {
            for (int j = 0; size < size-i-1; j++) {
                if(students[j].getAge()>students[i].getAge()){
                   Student temp=students[j];
                    students[j]=students[j+1];
                    students[j+1]=temp;
                }
            }
        }
    }
    public void  sortByScore(){
        List<Student> list=new ArrayList<>();
        for (Student s:students){
            list.add(s);
        }
       list.sort((s1,s2)->(int)(s1.getScore()-s2.getScore()));
        System.out.println(list);
    }
    public void showStudent(){
        Student s;
        for (int i = 0; i <size ; i++) {
            s=students[i];
            System.out.println(
                    s.getNum()+"\t"+s.getName()+"\t"+s.getAge()+"\t"+s.getScore()
            );
        }
    }
}
